<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px" v-show="showSearch">
            <el-form-item label="任务编号" prop="taskNum">
                <el-input v-model="queryParams.taskNum" placeholder="请输入任务编号" clearable />
            </el-form-item>
            <el-form-item label="任务名称" prop="taskName">
                <el-input v-model="queryParams.taskName" placeholder="请输入任务名称" clearable />
            </el-form-item>
            <el-form-item label="任务状态" prop="taskStatus">
                <el-select v-model="queryParams.taskStatus" placeholder="请选择任务状态" clearable>
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="省" prop="province">
                <el-select v-model="queryParams.province" placeholder="请选择省" @change="chooseProvince" clearable
                    value-key="id">
                    <el-option v-for="item in provinceData" :key="item.id" :label="item.name" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="市" prop="city">
                <el-select v-model="queryParams.city" placeholder="请选择市" @change="chooseCity" clearable value-key="id">
                    <el-option v-for="item in cityData" :key="item.id" :label="item.name" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="区/县" prop="area">
                <el-select v-model="queryParams.area" placeholder="请选择区/县" @change="chooseCounty" clearable value-key="id">
                    <el-option v-for="item in areaData" :key="item.id" :label="item.name" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleQuery">搜索</el-button>
                <el-button plain @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="dataList" stripe>
            <el-table-column label="任务编号" align="center" prop="taskNum" />
            <el-table-column label="任务名称" align="center" prop="taskName">
                <template #default="scope">
                    <span @click="handleDeatil(scope.row)"
                        style="color: var(--el-color-primary); cursor: pointer;">{{ scope.row.taskName }}</span>
                </template>
            </el-table-column>
            <el-table-column label="任务管理员" align="center" prop="taskManager" />
            <el-table-column label="任务状态" align="center" prop="taskStatus">
                <template #default="scope">
                    <span v-if="scope.row.taskStatus == '0'">未分配</span>
                    <span v-else-if="scope.row.taskStatus == '1'">进行中</span>
                    <span v-else-if="scope.row.taskStatus == '2'">审核中</span>
                    <span v-else-if="scope.row.taskStatus == '3'">已结束</span>
                </template>
            </el-table-column>
            <el-table-column label="承担小组" align="center" prop="groupName" />
            <el-table-column label="任务地区" align="center" prop="taskDistrict" show-overflow-tooltip />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="permission"
                width="300px">
                <template #default="scope">
                    <el-link type="primary" :underline="false" @click="handleDisasterAdd(scope.row)"
                        style="padding: 5px;">灾害情景分析</el-link>
                    <el-link type="primary" :underline="false" @click="handleAgelAdd(scope.row)"
                        style="padding: 5px;">年度风险应对策略建议</el-link>
                    <el-link type="primary" :underline="false" @click="handleEmergencyDisaster(scope.row)"
                        style="padding: 5px;">应急备灾对策</el-link>
                    <el-link type="primary" :underline="false" @click="handleEmergencyDisposal(scope.row)"
                        style="padding: 5px;">应急处置对策</el-link>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
            @pagination="getList" />

        <!-- 灾害情景分析弹出框 -->
        <el-dialog v-model="open" append-to-body>
            <p class="dialogTitle">灾害情景分析</p>
            <DisasterScenarios ref="disasters" :form="form" @getAreaList="getAreaList" @changeAreaList="changeAreaList" />
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="submitForm">确定</el-button>
                    <el-button plain @click="cancel">取消</el-button>
                </div>
            </template>
        </el-dialog>

        <!-- 年度风险应对策略建议弹出框 -->
        <el-dialog v-model="open1" append-to-body>
            <p class="dialogTitle">年度风险应对策略建议</p>
            <Agel ref="agels" :form1="form1" @getAreaList1="getAreaList1" @changeAreaList1="changeAreaList1" />
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="submitForm1">确定</el-button>
                    <el-button plain @click="cancel1">取消</el-button>
                </div>
            </template>
        </el-dialog>

        <!-- 应急备灾对策弹出框 -->
        <el-dialog v-model="open2" append-to-body>
            <p class="dialogTitle">应急备灾对策</p>
            <EmergencyDisaster ref="emergencyDisasters" :form2="form2" @getAreaList2="getAreaList2"
                @changeAreaList2="changeAreaList2" />
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="submitForm2">确定</el-button>
                    <el-button plain @click="cancel2">取消</el-button>
                </div>
            </template>
        </el-dialog>

        <!-- 应急处置对策弹出框 -->
        <el-dialog v-model="open3" append-to-body>
            <p class="dialogTitle">应急处置对策</p>
            <EmergencyDisposal ref="emergencyDisposals" :form3="form3" @getAreaList3="getAreaList3"
                @changeAreaList3="changeAreaList3" />
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="submitForm3">确定</el-button>
                    <el-button plain @click="cancel3">取消</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>
  
<script setup name="analyse">
import { getUserId } from '@/utils/auth'
import { ElMessage } from 'element-plus'
import { getProvince, getChildArea } from "@/api/system/division";
import { getAllQueryTaskList, saveDisasterScenario, saveAnnualRisk, saveEmergencyDisaster, saveEmergencyDisposal, getArea } from "@/api/suggestions/analyse.js";
import DisasterScenarios from "./disasterScenarios.vue";
import Agel from "./agel.vue";
import EmergencyDisaster from "./emergencyDisaster.vue";
import EmergencyDisposal from "./emergencyDisposal.vue";
const { proxy } = getCurrentInstance();
const dataList = ref([]);
const ids = ref();
const loading = ref(false);
const open = ref(false);
const open1 = ref(false);
const open2 = ref(false);
const open3 = ref(false);
const total = ref(0);
const showSearch = ref(true);
const provinceData = ref([]);//省
const cityData = ref([]);//市
const areaData = ref([]);//区、县
const permission = ref(true);
const disasters = ref();
const agels = ref();
const emergencyDisasters = ref();
const emergencyDisposals = ref();
const options = [{ value: "0", label: "未分配" }, { value: "1", label: "进行中" }, { value: "2", label: "审核中" }, { value: "3", label: "已结束" }];

const data = reactive({
    form: {
        taskNum: undefined,
        isCity: undefined,
        id: undefined,
        taskName: undefined,
        maintainer: undefined,
        maintainTime: undefined,
        taskDistrict: undefined,
        areaList: undefined,
    },
    form1: {
        taskNum: undefined,
        isCity: undefined,
        id: undefined,
        taskName: undefined,
        maintainer: undefined,
        maintainTime: undefined,
        taskDistrict: undefined,
        areaList: undefined,
    },
    form2: {
        taskNum: undefined,
        isCity: undefined,
        id: undefined,
        taskName: undefined,
        maintainer: undefined,
        maintainTime: undefined,
        taskDistrict: undefined,
        areaList: undefined,
    },
    form3: {
        taskNum: undefined,
        isCity: undefined,
        id: undefined,
        taskName: undefined,
        maintainer: undefined,
        maintainTime: undefined,
        taskDistrict: undefined,
        areaList: undefined,
    },
    queryParams: {
        page: 1,
        rows: 10,
        taskNum: undefined,
        taskName: undefined,
        taskStatus: undefined,
        province: undefined,
        city: undefined,
        area: undefined,
    },
})
const { queryParams, form, form1, form2, form3 } = toRefs(data)
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.page = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    dataList.value = [];
    cityData.value = [];
    areaData.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

watch(
    () => form.value.areaList,
    (value) => {
        form.value.areaList = value;
    }, { immediate: true }
)
watch(
    () => form1.value.areaList,
    (value) => {
        form1.value.areaList = value;
    }, { immediate: true }
)
watch(
    () => form2.value.areaList,
    (value) => {
        form2.value.areaList = value;
    }, { immediate: true }
)
watch(
    () => form3.value.areaList,
    (value) => {
        form3.value.areaList = value;
    }, { immediate: true }
)

/** 查询信息列表 */
function getList() {
    loading.value = true;
    //console.log(queryParams.value.province)
    const query = {
        ...queryParams.value,
        province: queryParams.value.province ? queryParams.value.province : '',
        city: queryParams.value.city ? queryParams.value.city : '',
        area: queryParams.value.area ? queryParams.value.area : '',
    }
    //console.log(query)
    getAllQueryTaskList(query).then(response => {
        dataList.value = response.data.rows;
        total.value = response.data.total;
        loading.value = false;
    });
}

// 打开 灾害情景分析
function handleDisasterAdd(row) {
    if (localStorage.getItem(row.id + '灾害情景分析')) {
        form.value.isCity = localStorage.getItem(row.id + '灾害情景分析');
    } else {
        form.value.isCity = "0";
    }
    form.value.taskName = row.taskName;
    form.value.taskNum = row.taskNum;
    form.value.id = row.id;
    form.value.maintainer = row.maintainer ? row.maintainer : JSON.parse(localStorage.getItem('userName'));
    form.value.maintainTime = row.maintainTime ? row.maintainTime : getNowFormatTime();
    form.value.taskDistrict = row.taskDistrict;
    getAreaData({ flag: form.value.isCity, taskDistrict: row.taskDistrict, suggestionName: '灾害情景分析', taskNum: form.value.taskNum });
    open.value = true;
    nextTick(() => {
        disasters.value.initActiveName();
        if (disasters.value.$refs["disasterScenariosRef"]) {
            disasters.value.$refs["disasterScenariosRef"].clearValidate();
        }
    })
}

// 打开 年度风险应对策略建议
function handleAgelAdd(row) {
    if (localStorage.getItem(row.id + '年度风险应对策略建议')) {
        form1.value.isCity = localStorage.getItem(row.id + '年度风险应对策略建议');
    } else {
        form1.value.isCity = "0";
    }
    form1.value.taskName = row.taskName;
    form1.value.taskNum = row.taskNum;
    form1.value.id = row.id;
    form1.value.maintainer = row.maintainer ? row.maintainer : JSON.parse(localStorage.getItem('userName'));
    form1.value.maintainTime = row.maintainTime ? row.maintainTime : getNowFormatTime();
    form1.value.taskDistrict = row.taskDistrict;
    getAreaData({ flag: form1.value.isCity, taskDistrict: row.taskDistrict, suggestionName: '年度风险应对策略建议', taskNum: form1.value.taskNum });
    open1.value = true;
    nextTick(() => {
        agels.value.initActiveName();
        if (agels.value.$refs["agelRef"]) {
            agels.value.$refs["agelRef"].clearValidate();
        }
    })
}

// 打开 应急备灾对策
function handleEmergencyDisaster(row) {
    if (localStorage.getItem(row.id + '应急备灾对策')) {
        form2.value.isCity = localStorage.getItem(row.id + '应急备灾对策');
    } else {
        form2.value.isCity = "0";
    }
    form2.value.taskName = row.taskName;
    form2.value.taskNum = row.taskNum;
    form2.value.id = row.id;
    form2.value.maintainer = row.maintainer ? row.maintainer : JSON.parse(localStorage.getItem('userName'));
    form2.value.maintainTime = row.maintainTime ? row.maintainTime : getNowFormatTime();
    form2.value.taskDistrict = row.taskDistrict;
    getAreaData({ flag: form2.value.isCity, taskDistrict: row.taskDistrict, suggestionName: '应急备灾对策', taskNum: form2.value.taskNum });
    open2.value = true;
    nextTick(() => {
        emergencyDisasters.value.initActiveName();
        if (emergencyDisasters.value.$refs["emergencyDisasterRef"]) {
            emergencyDisasters.value.$refs["emergencyDisasterRef"].clearValidate();
        }
    })
}

// 打开 应急处置对策
function handleEmergencyDisposal(row) {
    if (localStorage.getItem(row.id + '应急处置对策')) {
        form3.value.isCity = localStorage.getItem(row.id + '应急处置对策');
    } else {
        form3.value.isCity = "0";
    }
    form3.value.taskName = row.taskName;
    form3.value.taskNum = row.taskNum;
    form3.value.id = row.id;
    form3.value.maintainer = row.maintainer ? row.maintainer : JSON.parse(localStorage.getItem('userName'));
    form3.value.maintainTime = row.maintainTime ? row.maintainTime : getNowFormatTime();
    form3.value.taskDistrict = row.taskDistrict;
    getAreaData({ flag: form3.value.isCity, taskDistrict: row.taskDistrict, suggestionName: '应急处置对策', taskNum: form3.value.taskNum });
    open3.value = true;
    nextTick(() => {
        emergencyDisposals.value.initActiveName();
        if (emergencyDisposals.value.$refs["emergencyDisposalRef"]) {
            emergencyDisposals.value.$refs["emergencyDisposalRef"].clearValidate();
        }
    })
}

function getAreaList(val) {
    form.value.areaList = val;
}

function changeAreaList(val) {
    form.value.areaList = val;
}

function getAreaList1(val) {
    form1.value.areaList = val;
}

function changeAreaList1(val) {
    form1.value.areaList = val;
}

function getAreaList2(val) {
    form2.value.areaList = val;
}

function changeAreaList2(val) {
    form2.value.areaList = val;
}

function getAreaList3(val) {
    form3.value.areaList = val;
}

function changeAreaList3(val) {
    form3.value.areaList = val;
}

// 获取 区县或者地市
function getAreaData(isCity) {
    getArea(isCity).then(response => {
        // console.log(response.data);
        if (isCity.suggestionName == '灾害情景分析') {
            form.value.areaList = response.data['灾害情景分析'];
        } else if (isCity.suggestionName == '年度风险应对策略建议') {
            form1.value.areaList = response.data['年度风险应对策略建议'];
        } else if (isCity.suggestionName == '应急备灾对策') {
            form2.value.areaList = response.data['应急备灾对策'];
        } else if (isCity.suggestionName == '应急处置对策') {
            form3.value.areaList = response.data['应急处置对策'];
        }
    })
}


/** 查看方法*/
function detailDed(row) {
    reset();
    getDetail(row.hsdId)
}

/** 提交按钮 */
function submitForm() {
    disasters.value.getAreaList();
    disasters.value.$refs["disasterScenariosRef"].validate((valid, obj) => {
        if (!valid) {
            let newObj = {}
            newObj = most(Object.keys(obj))
            if (form.value.areaList[0].area) {
                const messageError = errorMessage(newObj, 'area', 'disasterScenariosRef', 5, 1);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form.value.areaList.forEach(item => {
                        item.maintainer = form.value.maintainer;
                        item.maintainTime = form.value.maintainTime;
                        item.taskNum = form.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveDisasterScenario(form.value.areaList).then(response => {
                        localStorage.setItem(form.value.id + '灾害情景分析', '0')
                        proxy.$modal.msgSuccess("保存成功");
                        open.value = false;
                        getList();
                    });
                }
            } else {
                const messageError = errorMessage(newObj, 'city', 'disasterScenariosRef', 5, 1);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form.value.areaList.forEach(item => {
                        item.maintainer = form.value.maintainer;
                        item.maintainTime = form.value.maintainTime;
                        item.taskNum = form.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveDisasterScenario(form.value.areaList).then(response => {
                        localStorage.setItem(form.value.id + '灾害情景分析', '1')
                        proxy.$modal.msgSuccess("保存成功");
                        open.value = false;
                        getList();
                    });
                }
            }
        } else {
            form.value.areaList.forEach(item => {
                item.maintainer = form.value.maintainer;
                item.maintainTime = form.value.maintainTime;
                item.taskNum = form.value.taskNum;
                item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                item.divisionFlag = item.area ? '0' : '1';
            })
            saveDisasterScenario(form.value.areaList).then(response => {
                localStorage.setItem(form.value.id + '灾害情景分析', form.value.areaList[0].area ? '0' : '1')
                proxy.$modal.msgSuccess("保存成功");
                open.value = false;
                getList();
            });
        }
    });
}

function submitForm1() {
    agels.value.getAreaList1();
    agels.value.$refs["agelRef"].validate((valid, obj) => {
        if (!valid) {
            let newObj = {}
            newObj = most(Object.keys(obj))
            if (form1.value.areaList[0].area) {
                const messageError = errorMessage(newObj, 'area', 'agelRef', 4, 2);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form1.value.areaList.forEach(item => {
                        item.maintainer = form1.value.maintainer;
                        item.maintainTime = form1.value.maintainTime;
                        item.taskNum = form1.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveAnnualRisk(form1.value.areaList).then(response => {
                        localStorage.setItem(form1.value.id + '年度风险应对策略建议', '0')
                        proxy.$modal.msgSuccess("保存成功");
                        open1.value = false;
                        getList();
                    });
                }
            } else {
                const messageError = errorMessage(newObj, 'city', 'agelRef', 4, 2);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form1.value.areaList.forEach(item => {
                        item.maintainer = form1.value.maintainer;
                        item.maintainTime = form1.value.maintainTime;
                        item.taskNum = form1.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveAnnualRisk(form1.value.areaList).then(response => {
                        localStorage.setItem(form1.value.id + '年度风险应对策略建议', '1')
                        proxy.$modal.msgSuccess("保存成功");
                        open1.value = false;
                        getList();
                    });
                }
            }
        } else {
            form1.value.areaList.forEach(item => {
                item.maintainer = form1.value.maintainer;
                item.maintainTime = form1.value.maintainTime;
                item.taskNum = form1.value.taskNum;
                item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                item.divisionFlag = item.area ? '0' : '1';
            })
            saveAnnualRisk(form1.value.areaList).then(response => {
                localStorage.setItem(form1.value.id + '年度风险应对策略建议', form1.value.areaList[0].area ? '0' : '1')
                proxy.$modal.msgSuccess("保存成功");
                open1.value = false;
                getList();
            });
        }
    });
}

function submitForm2() {
    emergencyDisasters.value.getAreaList2();
    emergencyDisasters.value.$refs["emergencyDisasterRef"].validate((valid, obj) => {
        if (!valid) {
            let newObj = {}
            newObj = most(Object.keys(obj))
            if (form2.value.areaList[0].area) {
                const messageError = errorMessage(newObj, 'area', 'emergencyDisasterRef', 8, 3);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form2.value.areaList.forEach(item => {
                        item.maintainer = form2.value.maintainer;
                        item.maintainTime = form2.value.maintainTime;
                        item.taskNum = form2.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveEmergencyDisaster(form2.value.areaList).then(response => {
                        localStorage.setItem(form2.value.id + '应急备灾对策', '0')
                        proxy.$modal.msgSuccess("保存成功");
                        open2.value = false;
                        getList();
                    });
                }
            } else {
                const messageError = errorMessage(newObj, 'city', 'emergencyDisasterRef', 8, 3);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form2.value.areaList.forEach(item => {
                        item.maintainer = form2.value.maintainer;
                        item.maintainTime = form2.value.maintainTime;
                        item.taskNum = form2.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveEmergencyDisaster(form2.value.areaList).then(response => {
                        localStorage.setItem(form2.value.id + '应急备灾对策', '1')
                        proxy.$modal.msgSuccess("保存成功");
                        open2.value = false;
                        getList();
                    });
                }
            }
        } else {
            form2.value.areaList.forEach(item => {
                item.maintainer = form2.value.maintainer;
                item.maintainTime = form2.value.maintainTime;
                item.taskNum = form2.value.taskNum;
                item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                item.divisionFlag = item.area ? '0' : '1';
            })
            saveEmergencyDisaster(form2.value.areaList).then(response => {
                localStorage.setItem(form2.value.id + '应急备灾对策', form2.value.areaList[0].area ? '0' : '1')
                proxy.$modal.msgSuccess("保存成功");
                open2.value = false;
                getList();
            });
        }
    });
}

function submitForm3() {
    emergencyDisposals.value.getAreaList3();
    emergencyDisposals.value.$refs["emergencyDisposalRef"].validate((valid, obj) => {
        if (!valid) {
            let newObj = {}
            newObj = most(Object.keys(obj))
            if (form3.value.areaList[0].area) {
                const messageError = errorMessage(newObj, 'area', 'emergencyDisposalRef', 9, 4);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form3.value.areaList.forEach(item => {
                        item.maintainer = form3.value.maintainer;
                        item.maintainTime = form3.value.maintainTime;
                        item.taskNum = form3.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveEmergencyDisposal(form3.value.areaList).then(response => {
                        localStorage.setItem(form3.value.id + '应急处置对策', '0')
                        proxy.$modal.msgSuccess("保存成功");
                        open3.value = false;
                        getList();
                    });
                }
            } else {
                const messageError = errorMessage(newObj, 'city', 'emergencyDisposalRef', 9, 4);
                if (messageError.length != 0) {
                    const msg = messageError.join('<br/><br/>')
                    ElMessage({
                        message: msg,
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                    })
                } else {
                    form3.value.areaList.forEach(item => {
                        item.maintainer = form3.value.maintainer;
                        item.maintainTime = form3.value.maintainTime;
                        item.taskNum = form3.value.taskNum;
                        item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                        item.divisionFlag = item.area ? '0' : '1';
                    })
                    saveEmergencyDisposal(form3.value.areaList).then(response => {
                        localStorage.setItem(form3.value.id + '应急处置对策', '1')
                        proxy.$modal.msgSuccess("保存成功");
                        open3.value = false;
                        getList();
                    });
                }
            }
        } else {
            form3.value.areaList.forEach(item => {
                item.maintainer = form3.value.maintainer;
                item.maintainTime = form3.value.maintainTime;
                item.taskNum = form3.value.taskNum;
                item.maintainerId = item.maintainerId ? item.maintainerId : getUserId();
                item.divisionFlag = item.area ? '0' : '1';
            })
            saveEmergencyDisposal(form3.value.areaList).then(response => {
                localStorage.setItem(form3.value.id + '应急处置对策', form3.value.areaList[0].area ? '0' : '1')
                proxy.$modal.msgSuccess("保存成功");
                open3.value = false;
                getList();
            });
        }
    });
}
// 错误校验出现的次数
function most(arrays) {
    console.log(arrays)
    let newObj = {};
    for (let i = 0; i < arrays.length; i++) {
        let val = arrays[i].substring(0, arrays[i].lastIndexOf('.'));
        newObj[val] === undefined ? newObj[val] = 1 : newObj[val]++;
    }
    return newObj;
}

// 返回报错信息提示
function errorMessage(newObj, name, ref, num, refName) {
    console.log(newObj)
    const arr = [];
    const clearRules = [];
    for (const val in newObj) {
        if (newObj[val] == num) {
            if (name == 'area') {
                arr.push(form.value.areaList[val.split('.')[1]].area + '所在地区未填写完整')
            } else {
                arr.push(form.value.areaList[val.split('.')[1]].city + '所在地区未填写完整')
            }
        } else {
            clearRules.push(val.split('.')[1])
        }
    }
    console.log(clearRules, '需要清除掉的地区');
    clearRuless(clearRules, ref, refName);
    return arr
}

// 清楚错误校验信息
function clearRuless(arr, ref, refName) {
    const newArr = [];
    for (let i = 0; i < arr.length; i++) {
        newArr.push('areaList.' + arr[i] + '.buildingDamage', 'areaList.' + arr[i] + '.casualties', 'areaList.' + arr[i] + '.geologicHazard', 'areaList.' + arr[i] + '.secondaryDisaster', 'areaList.' + arr[i] + '.earthquakeTraffic', 'areaList.' + arr[i] + '.otherDisaster')
    }
    newArr.forEach(item => {
        console.log(item, '清楚每一项');
        if (refName == 1) {
            disasters.value.$refs[ref].clearValidate(item)
        } else if (refName == 2) {
            agels.value.$refs[ref].clearValidate(item)
        } else if (refName == 3) {
            emergencyDisasters.value.$refs[ref].clearValidate(item)
        } else if (refName == 4) {
            emergencyDisposals.value.$refs[ref].clearValidate(item)
        }

    })
}

/** 取消按钮 */
function cancel() {
    open.value = false;
}
function cancel1() {
    open1.value = false;
}
function cancel2() {
    open2.value = false;
}
function cancel3() {
    open3.value = false;
}

/** 获取省列表 */
function getProvinceData() {
    getProvince().then((response) => {
        provinceData.value = response.data;
    });
}

function chooseProvince(value) {
    queryParams.value.city = null;
    queryParams.value.area = null;
    queryParams.value.province = value.name;
    cityData.value = [];
    areaData.value = [];
    getChildArea(value.id).then(response => {
        cityData.value = response.data;
    });
}

function chooseCity(value) {
    queryParams.value.city = value.name;
    queryParams.value.area = null;
    areaData.value = [];
    getChildArea(value.id).then((response) => {
        areaData.value = response.data;
    });
}

function chooseCounty(value) {
    queryParams.value.area = value.name;
}

//获取当前日期，格式YYYY-MM-DD
function getNowFormatDay(nowDate) {
    var char = "-";
    if (nowDate == null) {
        nowDate = new Date();
    }
    var day = nowDate.getDate();
    var month = nowDate.getMonth() + 1;//注意月份需要+1
    var year = nowDate.getFullYear();
    //补全0，并拼接
    return year + char + completeDate(month) + char + completeDate(day);
}
//获取当前时间，格式YYYY-MM-DD HH:mm:ss
function getNowFormatTime() {
    var nowDate = new Date();
    var colon = ":";
    var h = nowDate.getHours();
    var m = nowDate.getMinutes();
    var s = nowDate.getSeconds();
    //补全0，并拼接
    return getNowFormatDay(nowDate) + " " + completeDate(h) + colon + completeDate(m) + colon + completeDate(s);
}
//补全0
function completeDate(value) {
    return value < 10 ? "0" + value : value;
}

getProvinceData();
getList();
</script>
  
<style lang="scss" scoped>
.demo-tabs>.el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}</style>